#include <stdio.h>

#include "Common.h"
#include "Window.h"
#include "Internals.h"
#include "LCD.h"
#include "Gdi.h"
#include "Assert.h"
#include "Timer.h"

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

extern void DispBoot();
extern int	InitGUI();
#ifdef __cplusplus
}
#endif  /* __cplusplus */

static int LCDDrawHLine(int x1, int x2, int y);
static int LCDDrawVLine(int y1, int y2, int x);
static int LCDDrawRect(int x1,  int y1, int x2, int y2);
int LCDFillRect(int x1,  int y1, int x2, int y2, LCD_PIXEL_STATE pixel);
static void LCDDrawBitmap(int x, int y, int xsize, int ysize, int BytesPerLine, const BYTE* pData, int Diff, const BYTE *pTrans);


static int LCDDrawHLine(int x1, int x2, int y)
{
	MFCDrawHLine(x1, x2, y);
}
static int LCDDrawVLine(int y1, int y2, int x)
{
	MFCDrawVLine(y1, y2, x);
}
static int LCDDrawRect(int x1,  int y1, int x2, int y2)
{
	MFCDrawRect(x1, y1, x2, y2);
}
int LCDFillRect(int x1,  int y1, int x2, int y2, LCD_PIXEL_STATE pixel)
{
	MFCFillRect(x1, y1, x2, y2, pixel);
}
static void LCDDrawBitmap(int x, int y, int xsize, int ysize, int BytesPerLine, const BYTE* pData, int Diff, const BYTE *pTrans)
{
	MFCDrawBitmap( x, y, xsize, ysize, BytesPerLine, pData, Diff, pTrans);
}

const tLCDDEV_API LCD_APIList = {
    LCDDrawBitmap,
    LCDDrawRect,
    LCDDrawHLine,
    LCDDrawVLine,
    LCDFillRect,
    NULL
};

void Win_MFC_Init()
{
    InitGUI();
    //LG_ASSERT(0);
    DispBoot();
    //LG_ASSERT(0);	
}

void Win_MFC_UnInit()
{
   destroy_window(TRUE);
   TerminateGUI();
}


BOOL Win_MFC_Proc()
{
    MSG msg;

    if(GetMessage(&msg, HWND_DESKTOP))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
		return TRUE;
    }
	return FALSE;
}

BYTE msTimerStart(EN_MSTIMER_MODE msMode, WORD usDelay, PMSTIMER_CALLBACK_ROUTINE pmTimerRoutine, DWORD uiTarget)
{
	TimerStart(msMode, usDelay, pmTimerRoutine, uiTarget);
}

void msTimerStop (BYTE mscTimerID)
{
	TimerStop(mscTimerID);
}

int GuiMessage(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam)
{
	return SendMessage(hWnd, iMsg, wParam, lParam);
}